<template lang='pug'>
</template>
<script>
export default {
  name: "c_tech_threePoint",
  data() {
    return {
      viewer: null,
      Cesium: null,
      gp_tech_threePoint: null,
    };
  },
  props: {
    arrda: {
      type: Array,
      default: [],
    },
  },
  watch: {
    arrda: {
      handler() {
        if (this.Cesium && this.viewer) this.load();
      },
    },
    deep: true,
  },
  mounted() {
    let t = this;
    t.$nextTick(() => {
      t.viewer = t.$parent.viewer;
      t.Cesium = t.$parent.Cesium;
      let { Cesium, viewer } = this;
      t.gp_tech_threePoint = new Cesium.CustomDataSource("threePoint");
      viewer.dataSources.add(t.gp_tech_threePoint);
      // 停车场等点位
      t.load();
    });
  },
  methods: {
    load() {
      let t = this;
      let { Cesium, viewer } = this;
      this.gp_tech_threePoint.entities.removeAll();
      if (!this.gp_tech_threePoint) {
        // 设置一个实例
        this.gp_tech_threePoint = new Cesium.CustomDataSource("threePoint");
      }

      console.log(this.arrda);
      let _pt = this.arrda[0]
      let _pl = this.arrda[1]

      this.viewer.dataSources.add(this.gp_tech_threePoint);
      this.gp_tech_threePoint.entities.removeAll();
      // 区域渲染
      for (let i = 0; i < _pl.length; i++) {
        this.gp_tech_threePoint.entities.add(
          new Cesium.Entity({
            name: _pl[i].name,
            polygon: {
              hierarchy: Cesium.Cartesian3.fromDegreesArray(_pl[i].location),
              height: 0,
              material: Cesium.Color.SPRINGGREEN.withAlpha(0.4),
              outline: true,
              outlineColor: Cesium.Color.SLATEBLUE,
              height: 50,
            },
            label: {
              text: _pl[i].name, // "文字标签"
              font: "200 34px Yahei",
              scale: 0.5,
              pixelOffset: new Cesium.Cartesian2(0, -30), // 像素偏移
            },
            position: Cesium.Cartesian3.fromDegrees(
              _pl[i].location[0],
              _pl[i].location[1],
              50
            ),
          })
        );
      }
      // 点位渲染
      for (let i = 0; i < _pt.length; i++) {
        let src;
        if (_pt[i].srcUrl && _pt[i].srcUrl.length > 0) {
          src = this.$common.basePath + _pt[i].srcUrl;
        } else {
          src = this.$common.basePath + "static/img/billboard.png";
        }
        console.log(_pt[i]);

        this.gp_tech_threePoint.entities.add(
          new Cesium.Entity({
            name: _pt[i].name,
            billboard: {
              image: src,
              width: 30,
              height: 30,
              disableDepthTestDistance: Number.POSITIVE_INFINITY, //返回正无穷大
            },
            label: {
              text: _pt[i].name, // "文字标签"
              font: "200 24px Yahei",
              scale: 0.7,
              pixelOffset: new Cesium.Cartesian2(0, -30), // 像素偏移
            },
            position: Cesium.Cartesian3.fromDegrees(..._pt[i].point, 50),
          })
        );
      }
    },

  },
};
</script>